package com.shop2cn.iapi.sqdistributor.testcase;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.shop2cn.iapi.sqdistributor.parameter.request.SetDistributorLevelReq;
import com.shop2cn.iapi.sqdistributor.service.SetDistributorLevelCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.tag.P1;
import com.ymttest.database.model.sqdistributor.DistributorRelation;
import com.ymttest.database.sqlwapper.sqdistributor.DistributorRelationWrapper;
import com.ymttest.utils.TestDataManager;

public class Ts_SetDistributorLevel {
	
	//java接口
	private static SetDistributorLevelReq setDistributorLevelReq;
	private static SetDistributorLevelCall setDistributorLevelCall;

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("设置分销员等级");
	}

	@Before
	public void caseUp() {
		setDistributorLevelReq = new SetDistributorLevelReq();
		setDistributorLevelCall = new SetDistributorLevelCall();	
	}
	
	@AfterClass
	public static void tearDown() {
		Logger.generateResult(setDistributorLevelCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	
	public void verifyDb() throws Exception {
		
		DistributorRelationWrapper distributorRelationWrapper = new DistributorRelationWrapper();
		
		DistributorRelation actualResult = distributorRelationWrapper
				.selectByPrimaryKey(setDistributorLevelReq.getId());

		Logger.verifyEquals(setDistributorLevelReq.getDistributorLevelIndex(),
				actualResult.getDistributor_level_index(), "验证Distributor_level_index");
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SetDistributorLevel_001() {
		Logger.start(true, "分销员等级设置成功");
		
		try {
			
			setDistributorLevelReq.setDistributorLevelIndex(TestDataManager.getRandomIntNum(5));
			setDistributorLevelReq.setId(19098L);
			
			setDistributorLevelCall.setData(setDistributorLevelReq);
			setDistributorLevelCall.callService();
			
			Logger.verifyEquals(true, setDistributorLevelCall.getSuccess(), "验证success");
			
			verifyDb();
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}
